<template>
	<view class="box">
		<u-navbar title="搜索用户" :fixed="true" :placeholder="true" :safeAreaInsetTop="true" :autoBack="false"
			leftIconColor="#666" titleStyle="color:#333" bgColor="#E0DDDA" 
			@leftClick="leftClick"></u-navbar>
		<view class="wrap_top">
			<view class="search">
				<image src="/static/icon/iconsearch.png" mode=""></image>
				<input type="text" v-model="word" placeholder="请输入成员" @confirm="sub" />
			</view>
		</view>
		<view class="main">
			<view class="item" v-for="item in merberlist" :key="item.id" @click="add(item.account)">
				<image :src="item.head_img" mode=""></image>
				<text>{{item.nickname}}</text>
			</view>
		</view>
		<noDatas :xxxList="merberlist" :status="status"></noDatas>
		<view style="width: 750rpx;height: 88rpx;">

		</view>
	</view>
</template>

<script>
	import {
		groupMemberDetails,
		groupDetails,
		searchMember,
		addGroupMember
	} from "../../api/hx.js"
	import {
		getuserinfo
	} from "../../api/index.js"
	export default {
		data() {
			return {
				selectedIds: [],
				isshow: false,
				righttxt: "",
				word: "",
				page: 1,
				size: 20,
				status: 'loadmore', //加载前值为loadmore，加载中为loading，没有数据为nomore
				merberlist: [],
				groupid: "",
				tit: "",
				groupinfo: "",
				is_admin: "",
				user: {}
			}
		},
		onLoad(option) {
			this.groupid = option.id
		
			
		},
		onShow() {
		
		},
		methods: {
			add(accounts){
				addGroupMember({
					hx_group_id:this.groupid,
					account:accounts
				}).then(res=>{
					if(res.code==1){
						this.word=""
						this.page=1
						this.merberlist=[]
						// this.getlist()
					}
					uni.$u.toast(res.msg)
				})
			},
			getuser() {
				getuserinfo().then(res => {
					this.user = res.data
				})
			},

			leftClick() {
				//获取页面栈的长度
				const canNavBack = getCurrentPages()
				console.log(canNavBack.length);
				// 判断是否刷新了浏览器，刷新了浏览器，页面栈只有当前一个
				if (canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}
			},
			sub(){
				this.getlist()
			},
			getlist() {
				searchMember({
					hx_group_id: this.groupid,
					search_name: this.word,
					page:this.page
				}).then(res => {
					if (res.code == 1) {
						let list = res.data.data;
						this.merberlist = this.page == 1 ? list : this.merberlist.concat(list);
						console.log(this.merberlist);
						if (list.length < this.size) this.status = 'nomore';
						else this.status = 'loading';
					}
				})
			},
			leftClick() {
				//获取页面栈的长度
				const canNavBack = getCurrentPages()
				console.log(canNavBack.length);
				// 判断是否刷新了浏览器，刷新了浏览器，页面栈只有当前一个
				if (canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}
			},
			right() {
				this.isshow = true
				this.righttxt = "删除成员"
				if (this.selectedIds.length != 0) {
					this.selectedIds = []
					this.righttxt = "管理成员"
					uni.$u.toast("删除")
				}
			},
			checkboxChangeAll(e) {
				this.selectedIds = e.detail.value;
				console.log(this.selectedIds)
			},
		},
		onReachBottom() {
			if (this.status != 'nomore') {
				this.page = this.page + 1
				this.getlist()
			}

		}
	}
</script>
<style>
	page {
		background-color: #E0DDDA;
	}
</style>
<style lang="scss">
	.box {
		width: 750rpx;

	}

	/deep/ .u-navbar__content__right__text {
		color: #FF2CDF;
	}

	.wrap_top {
		width: 750rpx;
	}

	.search {
		width: 690rpx;
		height: 72rpx;
		background: #F2F2F2;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		margin: 30rpx auto;
		position: relative;

		>image {
			width: 32rpx;
			height: 30rpx;
			position: absolute;
			top: 22rpx;
			left: 34rpx;

		}

		>input {
			width: 620rpx;
			padding-left: 70rpx;
			height: 72rpx;
			font-weight: 400;
			font-size: 28rpx;
			color:#333;
		}
	}

	.main {
		width: 750rpx;

	}

	.item {
		width: 690rpx;
		margin: 0 auto;
		margin-top: 24rpx;
		display: flex;
		align-items: center;
		position: relative;

		>image {
			width: 84rpx;
			height: 84rpx;
			border-radius: 50%;
		}

		>text {
			font-weight: 400;
			font-size: 30rpx;
			color: #333;
			margin-left: 15rpx;
			max-width: 200rpx;
			white-space: nowrap;
			/* 防止文本换行 */
			overflow: hidden;
			/* 隐藏溢出的文本 */
			text-overflow: ellipsis;
			/* 当文本溢出时显示省略号 */
		}

		.tag {
			padding: 5rpx 10rpx 5rpx 10rpx;
			background: linear-gradient(274deg, #0014FF 0%, #8020EF 50%, #FF2CDF 100%);
			border-radius: 4rpx 4rpx 4rpx 4rpx;
			opacity: 0.5;
			font-size: 20rpx;
			color: rgba(255, 255, 255, 0.8);
			text-align: center;
			margin-left: 20rpx;
		}

	}

	/deep/.uni-checkbox-input {
		width: 30rpx;
		height: 30rpx;
		position: absolute;
		right: 40rpx;
		border-radius: 50%;
	}
</style>